package com.caesar.exer2;

/**
 * @author caesar
 * @date 2025/7/21
 * @Description:
 * @apiNote
 */
public class TestExer2 {
    public static void main(String[] args) throws InterruptedException {
        // 创建共享的列表对象
        SharedList sharedList = new SharedList();

        // 线程数量和每个线程添加元素的次数
        int threadCount = 5;
        int iterationsPerThread = 1000;

        // 创建并启动线程
        Thread[] threads = new Thread[threadCount];
        for (int i = 0; i < threadCount; i++) {
            threads[i] = new ListAddThread(sharedList, iterationsPerThread);
            threads[i].start();
        }

        // 等待所有线程执行完成
        for (Thread thread : threads) {
            thread.join();
        }

        // 验证结果
        int expectedSize = threadCount * iterationsPerThread;
        int actualSize = sharedList.getSize();

        System.out.println("实际集合大小: " + actualSize);
        System.out.println("预期大小: " + expectedSize);
        System.out.println("验证结果: " + (actualSize == expectedSize ? "正确" : "错误"));
    }
}
